package controller;

import bo.AdminLoginBO;
import com.opensymphony.xwork2.ActionSupport;
import dto.AdminLoginDTO;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;



public class AdminLoginServlet extends ActionSupport implements SessionAware {

    private Map session;

    private String ThongBao;

    private String username;
    private String pass;

    public String getPass() {
        return pass;
    }

    public String getThongBao() {
        return ThongBao;
    }

    public void setThongBao(String ThongBao) {
        this.ThongBao = ThongBao;
    }


    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }


    public AdminLoginServlet() {

    }

    @Override
    public String execute() throws Exception {

       String str = "success";
       if(this.username.equals(""))
       {
           ThongBao = "Fill the Username Field.";
           str = "error";
       }
       if(this.pass.equals(""))
       {
           ThongBao = "Fill the Password Field.";
           str = "error";
       }
       if(str.equals("success"))
       {
           AdminLoginBO adBO = new AdminLoginBO();
           boolean flag = adBO.login(username, pass);
           if(flag == false)
           {
               
               ThongBao = "Wrong Username or Password. Check again.";
               str = "error";
           }
           else
           {
               AdminLoginDTO adDTO = new AdminLoginDTO();
               adDTO = adBO.getAdminAccount(username);
               session.put("AdminLogin",adDTO);
           }
        }
       return str;
    }

    @Override
    public void setSession(Map map) {
        session = map;
    }



}